package cn.wolfcode.luowowo.mgrsite;

import cn.wolfcode.luowowo.cache.service.ITravelStatisRedisService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @author 猫教授
 * @date 2019/8/9 15:34
 */
@SpringBootApplication
@EnableScheduling
public class mgrsite {

    //    @Reference
//    private IStrategyDetailService strategyDetailService;
//    @Reference
//    private IStrategyStatisRedisService strategyStatisRedisService;
    @Reference
    private ITravelStatisRedisService travelStatisRedisService;

    public static void main(String[] args) {

        SpringApplication.run(mgrsite.class, args);

    }

    @EventListener
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        
        //这里我们要做的就是把数据库的数据同步到redis里面
        //这里统一先同步攻略相关的数据
        //第一步我们先拿出所有攻略的列表数据
     /*   System.out.println("开始同步");
        List<StrategyDetail> list = strategyDetailService.list();
        StrategyStatisVO statisVO = new StrategyStatisVO();
        list.forEach((Detail)->{

            //先进行判断看里面有没有,没有再同步,有就不同步
            String key ="STRATEGY_STATIC_VO:"+Detail.getId();
            boolean exists=strategyStatisRedisService.existsKey(key);
            if (exists==false) {
                System.out.println(Detail.getId());
                try {
                    BeanUtils.copyProperties(statisVO,Detail);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
                //有一些数据需要自己修改进去
                statisVO.setDestId(Detail.getDest().getId());
                statisVO.setDestName(Detail.getDest().getName());
                statisVO.setStrategyId(Detail.getId());
                //TODO 评论数待定
                strategyStatisRedisService.setStrategyStatisVO(statisVO);
            }
        });
        System.out.println("同步结束");*/

      /*  Set<String> keyList = travelStatisRedisService.getKeyList(RedisKeys.TRAVEL_STATIC_VO.join("*"));
        for (String key : keyList) {
            System.out.println("同步开始");
            TravelStatisVO vo = travelStatisRedisService.getVoByRedisKey(key);
            boolean hotHasInZset=travelStatisRedisService.hasInZset(RedisKeys.TRAVEL_HOT_SORT.getPrefix(),vo.getTravelId().toString());
            if (!hotHasInZset){
                travelStatisRedisService.addSortNum(RedisKeys.TRAVEL_HOT_SORT.getPrefix(),vo.getTravelId(),vo.getViewnum()+vo.getReplynum());
            }
            boolean commendHasInZset=travelStatisRedisService.hasInZset(RedisKeys.TRAVEL_COMMEND_SORT.getPrefix(),vo.getTravelId().toString());
            if (!commendHasInZset) {
                travelStatisRedisService.addSortNum(RedisKeys.TRAVEL_COMMEND_SORT.getPrefix(),vo.getTravelId(),vo.getFavornum()+vo.getThumbsupnum());
            }
            System.out.println("同步结束");
        }*/


    }





}
